package LambdaDemo;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2022-07-20
 * Time: 16:51
 */
//无返回值
@FunctionalInterface
interface NoParameterNoReturn {
    //注意：只能有一个方法
    void test();
    //void test2();
}
@FunctionalInterface
interface OneParameterNoReturn {
    //注意：只能有一个方法
    void test(int x);
}
@FunctionalInterface
interface MoreParameterNoReturn {
    //注意：只能有一个方法
    void test(int x,int y);
}
//有返回值
@FunctionalInterface
interface NoParameterReturn {
    //注意：只能有一个方法
    int test();
    //void test2();
}
@FunctionalInterface
interface OneParameterReturn {
    //注意：只能有一个方法
    int test(int x);
}
@FunctionalInterface
interface MoreParameterReturn {
    //注意：只能有一个方法
    int test(int x,int y);
}
public class Test {
    public static void main(String[] args) {
        //判断输入的数字是否是素数
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入一个数字");
        int n=sc.nextInt();
        int m=0;//记录因子个数
        for(int i=2;i<n;i++){
            if(n%i==0){
                m++;
            }
        }if(m==0){//没有因子的就是素数
            System.out.println("你输入的是素数");
        }else{
            System.out.println("你输入的不是素数");
        }
    }
    public static void main21(String[] args) {
        for (int i = 1; i <=100 ; i++) {

            int k=0;
            if(i>=2)
            {
                for ( k =2; k <i ; k++) {
                    if(i%k==0)
                        break;
                }
                if(k>=i)
                    System.out.println(i);
            }

        }
    }
    public static void main20(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int b = 0;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i + "*" + j + "=" + i * j + " ");

            }
            System.out.println();
        }
    }
    public static void main19(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n= scan.nextInt();
        for (int i = 0; i <=n ; i++) {
            int count=0;
            int j=0;
            j=i;
            while(j!=0)
            {
                j/=10;
                count++;
            }
            j=i;
            int c=0;
            int sum=0;

            while(j!=0)
            {
                c=j%10;
                sum+=Math.pow(c,count);

                j/=10;
            }
            if(i==sum)
            {
                System.out.println(i);

            }


        }
    }

    public static void main18(String[] args) {
        int ret = add(3,4);
        System.out.println(ret);
    }

    public static int add(int a, int b) {
        return (a + b);
    }

    public static double add(float a, float b) {
        return (a + b);
    }

    public static int sum(int x,int y){
        return x+y;
    }

    public static double sum(double x,double y,double z){
        return x+y+z;
    }

    public static void main17(String[] args) {
        System.out.println(sum(2,5));
        System.out.println(sum(2.1,3.2,1.0));
    }
    public static void main16(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 2; i < n ; i++) {
            if (n % i == 0 ) {
                System.out.println(n+"不是素数！");
                return;
            }
        }
        if(n==1){
            System.out.println(1+"不是素数");
        }else{
            System.out.println(n+"是素数！");
        }
    }
    public static void main15(String[] args) {
        //输入一个数 (类似于scanf)
        Scanner scanner=new Scanner(System.in);
        int a=scanner.nextInt();
        if(a<=0)
            System.out.println("输入错误");
        if(a==2||a==3)
            System.out.println("是素数");
        else {
            for (int i = 2; i <= (int)Math.sqrt(a); i++) {
                if((a%i)==0) {
                    System.out.println("不是素数");
                    break;
                }
                else {
                    System.out.println("是素数");
                    break;
                }
            }
        }
    }
    public static void main14(String[] args){
        int i = 1000;
        for ( i = 1000; i <=2000 ; i++) {
            if(i%4 == 0 && i%100!=0){
                System.out.println(+i);
            }
            if(i%400==0){
                System.out.println(+i);
            }
        }

    }
    public static void main13(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要查的数字：");
        int x = scanner.nextInt();
        int count = 0;

        //int 4 字节， 共 32 位
        for (int i = 0; i < 32; i++) {
            if (((x >> i) & 1) == 1) {
                count++;
            }
        }
        System.out.println(count);
    }
    public static void main12(String[] args) {

        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int i=0;
        System.out.println(n);
        for(i=2;i<n;i++){
            if(n % i == 0){
                break;
            }
        }
        if(i==n)
            System.out.println(n+"是素数");
        else
            System.out.println(n+"不是素数");


    }
    public static void main11(String[] args) {
        Scanner scan = new Scanner(System.in);
        Random random = new Random();
        int RandNum = random.nextInt(100);
//        System.out.println(RandNum);
        while (true) {
            System.out.println("请输入你要猜测的数值：");
            int num = scan.nextInt();
            if (num < RandNum) {
                System.out.println("你猜的数值小了");
            } else if (num > RandNum) {
                System.out.println("你猜的数值大了");

            } else {
                System.out.println("你猜对了！");
                break;
            }
        }
    }

        public static void main10(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n= scanner.nextInt();
        while(n!=0){
            System.out.print(n%10+" ");
            n/=10;
        }
    }


    public static void main9(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        for (int i = 2; i <= num; i++) {
            if(num%i==0&&(i!=num)){
                System.out.println(num +"不是素数");
                break;
            }
            if(i==num){
                System.out.println(num+"是素数");
            }
        }
    }
    private static int calc(String s){
        int i=0;
        Stack<String> stack=new Stack<>();
        while(i<s.length()){
            String ss=s.charAt(i)+"";
            if(ss.equals("*")){
                int sumLeft=Integer.parseInt(stack.pop());
                int sumRight=Integer.parseInt(s.charAt(++i)+"");
                stack.add(sumLeft*sumRight+"");
                i++;
            }else if(ss.equals("/")){
                int sumLeft=Integer.parseInt(stack.pop());
                int sumRight=Integer.parseInt(s.charAt(++i)+"");
                stack.add(sumLeft/sumRight+"");
                i++;
            }else{
                while(i<s.length()&&Integer.parseInt(ss)>=0&&Integer.parseInt(ss)<=9){
                    ss+=s.charAt(i+1)+"";
                    i+=2;
                }
                stack.add(ss);
                i++;
            }
        }
        Stack<String> stack2=new Stack<>();
        while(!stack.isEmpty()){
            stack2.add(stack.pop());
        }
        int sum=0;
        while(!stack2.isEmpty()){
            int left=Integer.parseInt(stack2.pop());
            if(stack2.isEmpty()){
                sum=left;
                break;
            }
            if(stack2.pop().equals("+")){
                int right=Integer.parseInt(stack2.pop());
                sum=left+right;
                stack2.add(left+right+"");
            }else if(stack2.pop().equals("-")){
                int right=Integer.parseInt(stack2.pop())+(-1);
                sum+=left+right;
                stack2.add(left+right+"");
            }
            if(stack2.isEmpty()){
                sum=left;
                break;
            }
        }
        return sum;
    }

    /*public static void main(String[] args){
     String s="6/2+3-3*4";
     int result=calc(s);
     System.out.println(result);
     Scanner sc=new Scanner(System.in);
     while(sc.hasNextLine()){
     String s="6/2+3+3*4";
     int result=calc(s);
     System.out.println(result);
     }
     }
     */

    //    public static void main8(String[] args) {
//        int a=11;
//        int[] arr = new int[]{1,2,3,2,1};
//        int[] basket = new int[100];
//        int i = 0,j = 0;
//        for(i = 0; i< arr.length; i++){
//            j = arr[i];
//            basket[j]+=1;
//        }
//        for(i = 0; i< basket.length; i++){
//            if(basket[i]==1){
//                System.out.println(i);
//                break;
//            }
//        }
//    }
    public static void main7(String[] args) {
        MoreParameterReturn moreParameterReturn=(x,y)-> x+y;
        System.out.println(moreParameterReturn.test(10,20));
    }
    public static void main6(String[] args) {
        OneParameterReturn oneParameterReturn=x->x;
        System.out.println(oneParameterReturn.test(10));
    }
    public static void main5(String[] args) {
        NoParameterReturn noParameterReturn=()->10;
        System.out.println(noParameterReturn.test());
    }
    public static void main4(String[] args) {
        MoreParameterNoReturn moreParameterNoReturn=(x,y)-> System.out.println(x+y);
        moreParameterNoReturn.test(1,2);
    }
    public static void main3(String[] args) {
        OneParameterNoReturn oneParameterNoReturn= System.out::println;
        oneParameterNoReturn.test(10);
    }
    public static void main2(String[] args) {
        NoParameterNoReturn noParameterNoReturn1=new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("fa");
            }
        };
        noParameterNoReturn1.test();

        NoParameterNoReturn noParameterNoReturn2=()->System.out.println("haha");
        noParameterNoReturn2.test();
    }
    public static void main1(String[] args) {
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        PriorityQueue<Integer> priorityQueue1=new PriorityQueue<>((o1,o2)->o2-o1);
    }
}
